package com.lmk;

import java.util.Scanner;

public class Project01 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int choose=0;
        String[] food={"火烧带鱼","鱼香肉丝","时令时蔬"};//菜品名字
        String[][] orders=new String[1024][];
        double[] prices={28.0,20.0,10.0};//菜品价格


        int[] Like={0,0,0};//菜品点赞次数
        do{
            System.out.println("欢迎使用“吃货联盟订单系统”");
            System.out.println("****************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看订单");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("****************************");
            System.out.print("请选择");
            choose = sc.nextInt();
            if(choose>0&&choose<6){
                switch (choose){
                    case 1:
                        System.out.println("******我要订餐******");
                        System.out.print("请输入订餐人姓名：");
                        String name=sc.next();
                        System.out.println("序号\t菜品\t\t价格");
                        for (int i = 0; i < food.length ; i++) {
                            System.out.println(i+1+food[i]+prices[i]);
                        }
                        int foodNum=0;
                        do {
                            System.out.print("请输入菜品编号");
                            foodNum=sc.nextInt();
                            if (foodNum<1||foodNum>food.length){
                                System.out.print("输入错误请重新输入");

                            }
                        }while (foodNum<1||foodNum>food.length);
                        int pcs=0;
                        do {
                            System.out.print("请输入份数");
                            pcs=sc.nextInt();
                            if (pcs<0){
                                System.out.print("输入错误请重新输入");

                            }
                        }while (pcs<0);
                        int time=0;
                        do {
                            System.out.print("请输入配送时间（10点到20点）");
                            time=sc.nextInt();
                            if (time<10||time>20){
                                System.out.println("输入错误 请重新输入时间");
                            }
                        }while (time<10||time>20);
                        System.out.println("请输入配送地址");
                        String add=sc.next();
                        System.out.println("订单成功");
                        System.out.println("您点的是"+food[foodNum-1]+pcs+"份");
                        System.out.println("您选择的配送时间是"+time);
                        double all=prices[foodNum-1]*pcs;
                        double sent=all>50?0:6;
                        System.out.println("外卖"+all+"元"+"配送费"+sent+"元"+"总计"+(all+sent)+"元");
                        for (int i = 0; i <orders.length ; i++) {
                           if(orders[i]==null){
                               orders[i]=new String[2];
                               orders[i][0]=name+"\t"+food[foodNum-1]+" "+pcs+"份\t"+time+"点\t"+ "\t"+(sent+all)+"元";
                               orders[i][1]="已预订";
                               break;
                           }
                        }
                        break;
                    case 2:
                        System.out.println("******查看订单******");
                        System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                        for (int i = 0; i <orders.length ; i++) {
                            if(orders[i]!=null){
                                System.out.println(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]);
                            }else {break;}

                        }break;
                    case 3:
                        System.out.println("******签收******");
                        System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                        for (int i = 0; i <orders.length ; i++) {
                            if(orders[i]!=null){
                                System.out.println(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]);

                            }else {
                                break;
                            }
                        }int num=0;
                        int end=0;
                        do{
                            System.out.println("请输入订单号");
                            for (int i = 0; i < orders.length ; i++) {
                                if(orders[i]==null){
                                    end=i;
                                    break;
                                }
                            }

                                num=sc.nextInt();
                                if (num<1||num>end){
                                    System.out.println("输入错误重新输入");
                                }else if(!"已预订".equals(orders[num-1][1])){
                                    System.out.println("订单已签收，不能重复签收");
                                }else{
                                    orders[num-1][1]="已完成";
                                    break;
                                }
                        }while(num<1||num>end||!"已完成".equals(orders[num-1][1]));
                        break;
                    case 4:
                        System.out.println("******签收******");
                        System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                        for (int i = 0; i <orders.length ; i++) {
                            if(orders[i]!=null){
                                System.out.println(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]);

                            }else {
                                break;
                            }
                        }int n = 0;
                        int e = 0;
                        do {
                            System.out.println("请输入要输出的订单序号");
                            for (int i = 0; i < orders.length; i++) {
                                if (orders[i] == null) {
                                    e = i;
                                    break;
                                }
                            }
                            n = sc.nextInt();
                            boolean isDeleted = false;

                            if (n < 1 || n > e) {
                                System.out.println("对不起，你的输入有误，请重新输入");
                            } else if (!"已完成".equals(orders[n-1][1])) {
                                System.out.println("不能删除未完成的订单");
                            } else {
                                boolean isDelete = true;
                                for (int i = n - 1; i < orders[i].length; i++) {
                                    if (n - 1 == orders.length) {
                                        orders[i] = null;
                                        isDelete = true;
                                    } else {
                                        orders[i] = orders[i + 1];//前移
                                        if (orders[i] == null) {
                                            isDelete = true;
                                            break;
                                        }
                                    }
                                }
                                if (isDelete) {
                                    break;
                                }
                            }
                        } while (n < 1 || n > e || !"已预订".equals(orders[n-1][ 1]));
                        break;
                    case 5:
                        System.out.println("***我要点赞***");
                        System.out.println("序号\t菜品\t\t单价\t\t点赞数");
                        for (int i = 0; i < food.length; i++) {
                            System.out.println(i+1+"\t"+food[i]+"\t"+prices[i]+"\t\t"+Like[i]+"次点赞");
                        }
                        int d;
                        do {
                            System.out.println("请选择你要点赞的菜品");
                            d = sc.nextInt();
                            if (d < 1 || d > Like.length) {
                                System.out.println("输入错误请重新输入");
                            } else {
                                Like[d - 1]++;
                            }
                        }while (d < 1 || d > Like.length);
                        break;
                    default:



                }
                System.out.println("按0返回上级页面");
                choose=sc.nextInt();
            }else {
                break;
            }

        }while (choose==0);
        System.out.println("欢迎使用下次光临");

    }
}
